package com.ruoyi.logistic.service.impl;

import com.github.pagehelper.PageHelper;
import com.ruoyi.logistic.domain.NetworkUndertakeCentreLevyCollect;
import com.ruoyi.logistic.domain.NetworkUndertakeCentreLevyDetail;
import com.ruoyi.logistic.domain.PageDate;
import com.ruoyi.logistic.domain.vo.NetworkUndertakeCentreDetailVo;
import com.ruoyi.logistic.domain.vo.NetworkUndertakeCentreLevyCollectVo;
import com.ruoyi.logistic.mapper.NetworkUndertakeCentreLevyCollectMapper;
import com.ruoyi.logistic.mapper.NetworkUndertakeCentreLevyDetailMapper;
import com.ruoyi.logistic.service.NetworkUndertakeCentreLevyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class NetworkUndertakeCentreLevyServiceImpl implements NetworkUndertakeCentreLevyService {
    @Autowired
    private NetworkUndertakeCentreLevyDetailMapper networkUndertakeCentreLevyDetailMapper;
    @Autowired
    private NetworkUndertakeCentreLevyCollectMapper networkUndertakeCentreLevyCollectMapper;
    @Override
    public List<NetworkUndertakeCentreLevyDetail> selectAll(PageDate pageDate) {
        PageHelper.startPage(pageDate);
        return networkUndertakeCentreLevyDetailMapper.selectAll();
    }

    @Override
    public Boolean insert(NetworkUndertakeCentreLevyDetail networkUndertakeCentreLevyDetail) {
        return networkUndertakeCentreLevyDetailMapper.insert(networkUndertakeCentreLevyDetail);
    }

    @Override
    public Boolean update(NetworkUndertakeCentreLevyDetail networkUndertakeCentreLevyDetail) {
        return networkUndertakeCentreLevyDetailMapper.update(networkUndertakeCentreLevyDetail);
    }

    @Override
    public Boolean deleteById(Integer id) {
        return networkUndertakeCentreLevyDetailMapper.deleteById(id);
    }

    @Override
    public List<NetworkUndertakeCentreLevyDetail> search(NetworkUndertakeCentreDetailVo networkUndertakeCentreDetailVo) {
        PageHelper.startPage(networkUndertakeCentreDetailVo.getPageDate());
        return networkUndertakeCentreLevyDetailMapper.search(networkUndertakeCentreDetailVo);
    }

    @Override
    public List<NetworkUndertakeCentreLevyCollect> collect(NetworkUndertakeCentreLevyCollectVo networkUndertakeCentreLevyCollectVo) {
        PageHelper.startPage(networkUndertakeCentreLevyCollectVo.getPageDate());
        List<NetworkUndertakeCentreLevyCollect> levyCollectList = networkUndertakeCentreLevyCollectMapper.collect(networkUndertakeCentreLevyCollectVo);
        assert levyCollectList != null;
        for (NetworkUndertakeCentreLevyCollect levyCollect : levyCollectList){
            if (networkUndertakeCentreLevyCollectVo.getCollectDimensionality() == 1){
                levyCollect.setSettleDate(networkUndertakeCentreLevyCollectVo.getTime() + "");
            }else {
                levyCollect.setSettleDate(networkUndertakeCentreLevyCollectVo.getMonth());
            }
        }
        return levyCollectList;
    }
}
